package com.bsoft.gol.editor.controller;


import hcn.util.BaseResponse;
import com.bsoft.gol.editor.editor.EditorDisplayLogic;
import hcn.util.ResultCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.bsoft.gol.editor.service.EditorDisplayLogicApi;
import com.bsoft.gol.editor.utils.CommonUtils;

import java.util.List;
import java.util.Map;

/**
 * @author zhangjie
 * @date 2019/6/21
 */
@RestController
@RequestMapping(value = "/api/auth/editorDisplayLogic")
public class EditorDisplayLogicController {

    @Autowired
    private EditorDisplayLogicApi editorDisplayLogicApi;

    /**
     * 显示逻辑新增 包括批量
     * @param req
     * @return
     */
    @RequestMapping("/add")
    public BaseResponse<String> add(@RequestBody EditorDisplayLogic req) {
        BaseResponse<String> response = new BaseResponse<>();
        // 批量
        if (CommonUtils.isNull(req.getTitleId())) {
            response.setCode(ResultCode.PARAMETERS_EMPTY);
            response.setMessage("传入参数不能为空");
            return response;
        }
        Map<String, Object> resMap = editorDisplayLogicApi.saveBatch(req);

        if(!resMap.get("code").equals(ResultCode.SUCCESS)){
            response.setCode(ResultCode.ERROR);
            response.setMessage("操作失败");
        }
        return response;
    }

    /**
     * 显示逻辑删除
     * @param req
     * @return
     */
    @RequestMapping("/delete")
    public BaseResponse<String> delete(@RequestBody EditorDisplayLogic req) {
        BaseResponse<String> response = new BaseResponse<>();
        if (CommonUtils.isNull(req.getDisplayId())) {
            response.setCode(ResultCode.PARAMETERS_EMPTY);
            response.setMessage("传入参数不能为空");
            return response;
        }
        editorDisplayLogicApi.deleteDisplayLogic(req);
        response.setMessage("删除成功");
        return response;
    }

    /**
     * 显示逻辑列表
     * @param req
     * @return
     */
    @RequestMapping("/list")
    public BaseResponse<List<EditorDisplayLogic>> list(@RequestBody EditorDisplayLogic req) {
        BaseResponse<List<EditorDisplayLogic>> response = new BaseResponse<List<EditorDisplayLogic>>();
        if (CommonUtils.isNull(req.getTitleId())) {
            response.setCode(ResultCode.PARAMETERS_EMPTY);
            response.setMessage("传入参数不能为空");
            return response;
        }
        List<EditorDisplayLogic> editorDisplayLogicResList = editorDisplayLogicApi.list(req);
        response.setData(editorDisplayLogicResList);
        return response;
    }

}
